package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.vo.TimeVo;
import com.zzyl.vo.VisitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description CustomerResevation
 * @Author Wen Jie
 * @Date 2024-09-14
 */
@Slf4j
@RestController
@Api(tags = "客户预约")
@RequestMapping("/customer/reservation")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CustomerReservationService customerReservationService;
    @PostMapping
    @ApiOperation(value = "客户预约")
    public ResponseResult addCustomerReservation(@RequestBody VisitVo visitVo) {
        customerReservationService.addCustomerReservation(visitVo);
        return success("预约成功");
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询预约信息")
    public ResponseResult<PageResponse<VisitVo>> selectByPage(@ApiParam(value = "页码", required = true) @RequestParam(defaultValue = "1") Integer pageNum,
                                                              @ApiParam(value = "每页数量", required = true)@RequestParam(defaultValue = "10") Integer pageSize,
                                                              @ApiParam(value = "状态") @RequestParam(required = false) Integer status) {
       PageResponse<VisitVo> pageResponse = customerReservationService.selectByPage(pageNum, pageSize,status);
       return success(pageResponse);
    }
    @GetMapping("/cancelled-count")
    @ApiOperation(value = "取消预约数量")
    public ResponseResult cancelledCount() {
        int count =  customerReservationService.cancelledCount();
        return success(count);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation(value = "取消预约")
    public ResponseResult cancel(@ApiParam(value = "预约id", required = true) @PathVariable Long id) {
        customerReservationService.cancel(id);
        return success("取消成功");
    }

    @GetMapping("/countByTime")
    @ApiOperation(value = "根据时间戳查询数量")
    public ResponseResult<List<TimeVo>> countByTimestamp(@ApiParam(value = "时间戳", required = true) @RequestParam Long time) {
        List<TimeVo> count = customerReservationService.countByTime(time);
        if (count.isEmpty()) {
            return error("没有数据");
        }
        return success(count);
    }

}
